package net.lab1024.sa.admin.module.app.controller;

import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import net.lab1024.sa.admin.module.app.req.MiniBindUserReq;
import net.lab1024.sa.admin.module.app.req.WxLoginFormReq;
import net.lab1024.sa.admin.module.app.rsp.LoginByPasswordRsp;
import net.lab1024.sa.admin.module.app.service.AppLoginService;
import net.lab1024.sa.admin.module.system.login.service.LoginService;
import net.lab1024.sa.base.common.annoation.NoNeedLogin;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

/**
 * 类的描述
 *
 * @author guolong.zhang
 * @date 2025/02/09 17:25
 **/
@RestController
@Tag(name = "app-登录")
@RequestMapping("app")
public class AppLoginController {

    @Autowired
    private AppLoginService loginService;

    @NoNeedLogin
    @Operation(summary = "小程序获取信息")
    @PostMapping("/open/getInfo")
    public ResponseDTO<WxMaJscode2SessionResult> openLogin(@RequestBody @Valid WxLoginFormReq openLoginReq){
        return ResponseDTO.ok(loginService.miniOpenLogin(openLoginReq.getCode()));
    }

    @NoNeedLogin
    @Operation(summary = "小程序快捷登录")
    @PostMapping("/open/bind")
    public ResponseDTO<LoginByPasswordRsp> openBind(@RequestBody @Valid MiniBindUserReq wxUserInfoBindReq) {
        return loginService.bindUser(wxUserInfoBindReq);
    }
    @NoNeedLogin
    @Operation(summary = "微信一键登录")
    @PostMapping("/open/wxLogin")
    public ResponseDTO<LoginByPasswordRsp> wxLogin(@RequestBody @Valid WxLoginFormReq req) {
        return loginService.wxLogin(req);
    }

}
